<template>
  <div class="banner-image" @mouseenter="isHover = true" @mouseleave="isHover = false">
    <div class="banner-image__image" 
      :style="{backgroundImage: 'url(' + modelValue?.data?.imgSrc + ')', 'background-position': 'center'}"
    >
      <div class="banner-image__title is-zh">
        {{ modelValue?.data?.title }}
      </div>
    </div>

    <Operate v-if="!isPreview" v-model:show="isHover" @handle-edit="showSetting = true" @handle-delete="handleDelete" @handle-copy="handleCopy" @handle-paste="handlePaste"></Operate>
  </div>

  <Setting v-if="!isPreview" v-model:show="showSetting" :data="modelValue"></Setting>
</template>

<script lang="ts" setup> 
import { ref } from 'vue'
import { randomString } from '@/utils/common'
import Operate from '@/common/Operate/index.vue'
import Setting from './setting.vue'


// 定义组件名称
defineOptions({
  name: 'BannerImage'
})

const props = defineProps({
  modelValue: {
    type: Object,
    default: () => {}
  },

  // 是否预览
  isPreview: {
    type: Boolean,
    default: true
  }
})

const emit = defineEmits(['update:modelValue', 'handleDelete', 'handleCopy', 'handlePaste'])

const handleInit = () => {
  if (props.modelValue && props.modelValue.data) return // 有数据不用初始化
  const data = {
    id: props.modelValue?.id || randomString(),
    type: 'BannerImage',
    data: {
      title: 'About YWIES',
      imgSrc: 'https://osswebsite-test.cedim.cn/ywies-tx/static-images/about-ywies/01_About_YWIES_1_Header.jpg'
    }
  }
  emit('update:modelValue', data)
} 

const isHover = ref<boolean>(false);
const showSetting = ref<boolean>(false);

const handleDelete = () => {
  emit('handleDelete', props.modelValue.id)
}

const handleCopy = () => {
  emit('handleCopy', props.modelValue)
}

const handlePaste = (type: string) => {
  emit('handlePaste', type)
}

handleInit()
</script>

<style lang="scss" scoped>
.banner-image {
  position: relative;
}

.banner-image__image {
  height: 340px;
  background-size: cover;
  background-repeat: no-repeat;
  background-image: linear-gradient(184.08deg,rgba(0,0,0,.427) 21.79%,transparent 96.67%),var(--bg-image);
  display: flex;
  flex-direction: column;
  align-items: center;
}

@media (max-width: 1279.98px) {
  .banner-image__image {
    height: clamp(200px,(100vw - 576px)/5 + 200px,340px);
  }
}

@media (max-width: 575.98px) {
  .banner-image__image {
    height: 200px;
  }
}

.banner-image.has-quick-links {
  padding-bottom: 38px;
}

.banner-image__title {
  font-size: 60px;
  line-height: 1.166;
  font-weight: 500;
  color: #fff;
  text-shadow: 0 0 10px rgba(130,130,140,.12);
  padding-top: 166px;
}

@media (max-width: 1279.98px) {
  .banner-image__title {
    padding-top: clamp(106px,(100vw - 576px)/11.73 + 106px,166px);
  }
}

@media (max-width: 1023.98px) {
  .banner-image__title {
    font-size: 36px;
  }
}

@media (max-width: 575.98px) {
  .banner-image__title {
    font-size: 40px;
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: .02em;
    padding-top: 106px;
  }
}

@media (max-width: 575.98px) and (max-width: 1023.98px) {
  .banner-image__title {
    font-size: 32px;
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: .02em;
  }
}

@media (max-width: 575.98px) and (max-width: 767.98px) {
  .banner-image__title {
    font-size: 24px;
    line-height: 1.09;
  }
}

.banner-image__title.is-zh {
  font-weight: 700;
}
</style>